home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / GIMP 2.6.8 / gimp-2.6.8-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / perspective-shadow.scm < prev    next >
Text File  |  2009-12-15  |  8KB  |  216 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ;
  18. ;
  19. ; perspective-shadow.scm   version 1.2   2000/11/08
  20. ;
  21. ; Copyright (C) 1997-2000 Sven Neumann <sven@gimp.org>
  22. ;
  23. ;
  24. ; Adds a perspective shadow of the current selection or alpha-channel
  25. ; as a layer below the active layer
  26. ;
  27.  
  28. (define (script-fu-perspective-shadow image
  29.                                       drawable
  30.                                       alpha
  31.                                       rel-distance
  32.                                       rel-length
  33.                                       shadow-blur
  34.                                       shadow-color
  35.                                       shadow-opacity
  36.                                       interpolation
  37.                                       allow-resize)
  38.   (let* (
  39.         (shadow-blur (max shadow-blur 0))
  40.         (shadow-opacity (min shadow-opacity 100))
  41.         (shadow-opacity (max shadow-opacity 0))
  42.         (rel-length (abs rel-length))
  43.         (alpha (* (/ alpha 180) *pi*))
  44.         (type (car (gimp-drawable-type-with-alpha drawable)))
  45.         (image-width (car (gimp-image-width image)))
  46.         (image-height (car (gimp-image-height image)))
  47.         (from-selection 0)
  48.         (active-selection 0)
  49.         (shadow-layer 0)
  50.         )
  51.  
  52.   (gimp-context-push)
  53.  
  54.   (if (> rel-distance 24) (set! rel-distance 999999))
  55.   (if (= rel-distance rel-length) (set! rel-distance (+ rel-distance 0.01)))
  56.  
  57.   (gimp-image-undo-group-start image)
  58.  
  59.   (gimp-layer-add-alpha drawable)
  60.   (if (= (car (gimp-selection-is-empty image)) TRUE)
  61.       (begin
  62.         (gimp-selection-layer-alpha drawable)
  63.         (set! from-selection FALSE))
  64.       (begin
  65.         (set! from-selection TRUE)
  66.         (set! active-selection (car (gimp-selection-save image)))))
  67.  
  68.   (let* ((selection-bounds (gimp-selection-bounds image))
  69.          (select-offset-x (cadr selection-bounds))
  70.          (select-offset-y (caddr selection-bounds))
  71.          (select-width (- (cadr (cddr selection-bounds)) select-offset-x))
  72.          (select-height (- (caddr (cddr selection-bounds)) select-offset-y))
  73.  
  74.          (abs-length (* rel-length select-height))
  75.          (abs-distance (* rel-distance select-height))
  76.          (half-bottom-width (/ select-width 2))
  77.          (half-top-width (* half-bottom-width
  78.                           (/ (- rel-distance rel-length) rel-distance)))
  79.  
  80.          (x0 (+ select-offset-x (+ (- half-bottom-width half-top-width)
  81.                                  (* (cos alpha) abs-length))))
  82.          (y0 (+ select-offset-y (- select-height
  83.                                  (* (sin alpha) abs-length))))
  84.          (x1 (+ x0 (* 2 half-top-width)))
  85.          (y1 y0)
  86.          (x2 select-offset-x)
  87.          (y2 (+ select-offset-y select-height))
  88.          (x3 (+ x2 select-width))
  89.          (y3 y2)
  90.  
  91.          (shadow-width (+ (- (max x1 x3) (min x0 x2)) (* 2 shadow-blur)))
  92.          (shadow-height (+ (- (max y1 y3) (min y0 y2)) (* 2 shadow-blur)))
  93.          (shadow-offset-x (- (min x0 x2) shadow-blur))
  94.          (shadow-offset-y (- (min y0 y2) shadow-blur)))
  95.  
  96.  
  97.     (set! shadow-layer (car (gimp-layer-new image
  98.                                             select-width
  99.                                             select-height
  100.                                             type
  101.                                             "Perspective Shadow"
  102.                                             shadow-opacity
  103.                                             NORMAL-MODE)))
  104.  
  105.  
  106.     (gimp-image-add-layer image shadow-layer -1)
  107.     (gimp-layer-set-offsets shadow-layer select-offset-x select-offset-y)
  108.     (gimp-drawable-fill shadow-layer TRANSPARENT-FILL)
  109.     (gimp-context-set-background shadow-color)
  110.     (gimp-edit-fill shadow-layer BACKGROUND-FILL)
  111.     (gimp-selection-none image)
  112.  
  113.     (if (= allow-resize TRUE)
  114.         (let* ((new-image-width image-width)
  115.                (new-image-height image-height)
  116.                (image-offset-x 0)
  117.                (image-offset-y 0))
  118.  
  119.           (if (< shadow-offset-x 0)
  120.               (begin
  121.                 (set! image-offset-x (abs shadow-offset-x))
  122.                 (set! new-image-width (+ new-image-width image-offset-x))
  123.                 ; adjust to new coordinate system
  124.                 (set! x0 (+ x0 image-offset-x))
  125.                 (set! x1 (+ x1 image-offset-x))
  126.                 (set! x2 (+ x2 image-offset-x))
  127.                 (set! x3 (+ x3 image-offset-x))
  128.               ))
  129.  
  130.           (if (< shadow-offset-y 0)
  131.               (begin
  132.                 (set! image-offset-y (abs shadow-offset-y))
  133.                 (set! new-image-height (+ new-image-height image-offset-y))
  134.                 ; adjust to new coordinate system
  135.                 (set! y0 (+ y0 image-offset-y))
  136.                 (set! y1 (+ y1 image-offset-y))
  137.                 (set! y2 (+ y2 image-offset-y))
  138.                 (set! y3 (+ y3 image-offset-y))
  139.               ))
  140.  
  141.           (if (> (+ shadow-width shadow-offset-x) new-image-width)
  142.               (set! new-image-width (+ shadow-width shadow-offset-x)))
  143.  
  144.           (if (> (+ shadow-height shadow-offset-y) new-image-height)
  145.               (set! new-image-height (+ shadow-height shadow-offset-y)))
  146.           (gimp-image-resize image
  147.                              new-image-width
  148.                              new-image-height
  149.                              image-offset-x
  150.                              image-offset-y)))
  151.  
  152.     (gimp-drawable-transform-perspective shadow-layer
  153.                       x0 y0
  154.                       x1 y1
  155.                       x2 y2
  156.                       x3 y3
  157.                       TRANSFORM-FORWARD
  158.                       interpolation
  159.                       TRUE 3 TRANSFORM-RESIZE-ADJUST)
  160.  
  161.     (if (>= shadow-blur 1.0)
  162.         (begin
  163.           (gimp-layer-set-lock-alpha shadow-layer FALSE)
  164.           (gimp-layer-resize shadow-layer
  165.                              shadow-width
  166.                              shadow-height
  167.                              shadow-blur
  168.                              shadow-blur)
  169.           (plug-in-gauss-rle RUN-NONINTERACTIVE
  170.                              image
  171.                              shadow-layer
  172.                              shadow-blur
  173.                              TRUE
  174.                              TRUE))))
  175.  
  176.   (if (= from-selection TRUE)
  177.       (begin
  178.         (gimp-selection-load active-selection)
  179.         (gimp-edit-clear shadow-layer)
  180.         (gimp-image-remove-channel image active-selection)))
  181.  
  182.   (if (and
  183.        (= (car (gimp-layer-is-floating-sel drawable)) 0)
  184.        (= from-selection FALSE))
  185.       (gimp-image-raise-layer image drawable))
  186.  
  187.   (gimp-image-set-active-layer image drawable)
  188.   (gimp-image-undo-group-end image)
  189.   (gimp-displays-flush)
  190.  
  191.   (gimp-context-pop)
  192.   )
  193. )
  194.  
  195. (script-fu-register "script-fu-perspective-shadow"
  196.   _"_Perspective..."
  197.   _"Add a perspective shadow to the selected region (or alpha)"
  198.   "Sven Neumann <sven@gimp.org>"
  199.   "Sven Neumann"
  200.   "2000/11/08"
  201.   "RGB* GRAY*"
  202.   SF-IMAGE       "Image"                        0
  203.   SF-DRAWABLE    "Drawable"                     0
  204.   SF-ADJUSTMENT _"Angle"                        '(45 0 180 1 10 1 0)
  205.   SF-ADJUSTMENT _"Relative distance of horizon" '(5 0.1 24.1 0.1 1 1 1)
  206.   SF-ADJUSTMENT _"Relative length of shadow"    '(1 0.1 24   0.1 1 1 1)
  207.   SF-ADJUSTMENT _"Blur radius"                  '(3 0 1024 1 10 0 0)
  208.   SF-COLOR      _"Color"                        '(0 0 0)
  209.   SF-ADJUSTMENT _"Opacity"                      '(80 0 100 1 10 0 0)
  210.   SF-ENUM       _"Interpolation"                '("InterpolationType" "linear")
  211.   SF-TOGGLE     _"Allow resizing"               FALSE
  212. )
  213.  
  214. (script-fu-menu-register "script-fu-perspective-shadow"
  215.                          "<Image>/Filters/Light and Shadow/Shadow")
  216.